package com.inmobi.commons.uid;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.Settings.Secure;
import android.provider.Settings.System;
import com.inmobi.commons.internal.Base64;
import com.inmobi.commons.internal.Log;
import java.math.BigInteger;
import java.security.KeyFactory;
import java.security.MessageDigest;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.RSAPublicKeySpec;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;

public class UIDHelper
{
  private static final Uri a = Uri.parse("content://com.facebook.katana.provider.AttributionIdProvider");
  public static String appId = null;

  static String a(String paramString1, String paramString2)
  {
    try
    {
      byte[] arrayOfByte1 = paramString1.getBytes("UTF-8");
      byte[] arrayOfByte2 = new byte[arrayOfByte1.length];
      byte[] arrayOfByte3 = paramString2.getBytes("UTF-8");
      for (int i = 0; i < arrayOfByte1.length; i++)
        arrayOfByte2[i] = ((byte)(arrayOfByte1[i] ^ arrayOfByte3[(i % arrayOfByte3.length)]));
      String str = new String(Base64.encode(arrayOfByte2, 2), "UTF-8");
      return str;
    }
    catch (Exception localException)
    {
      Log.debug("IMCOMMONS_3.7.0", "Exception in xor with random integer", localException);
    }
    return "";
  }

  private static byte[] a(byte[] paramArrayOfByte, int paramInt, Cipher paramCipher)
    throws IllegalBlockSizeException, BadPaddingException
  {
    new byte[0];
    byte[] arrayOfByte1 = new byte[0];
    if (paramInt == 1);
    int i = paramArrayOfByte.length;
    byte[] arrayOfByte2 = new byte[64];
    byte[] arrayOfByte3 = arrayOfByte1;
    int j = 0;
    if (j < i)
      if ((j > 0) && (j % 64 == 0))
      {
        arrayOfByte3 = a(arrayOfByte3, paramCipher.doFinal(arrayOfByte2));
        if (j + 64 <= i)
          break label117;
      }
    label117: for (int k = i - j; ; k = 64)
    {
      arrayOfByte2 = new byte[k];
      arrayOfByte2[(j % 64)] = paramArrayOfByte[j];
      j++;
      break;
      return a(arrayOfByte3, paramCipher.doFinal(arrayOfByte2));
    }
  }

  private static byte[] a(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2)
  {
    byte[] arrayOfByte = new byte[paramArrayOfByte1.length + paramArrayOfByte2.length];
    int k;
    for (int i = 0; ; i++)
    {
      int j = paramArrayOfByte1.length;
      k = 0;
      if (i >= j)
        break;
      arrayOfByte[i] = paramArrayOfByte1[i];
    }
    while (k < paramArrayOfByte2.length)
    {
      arrayOfByte[(k + paramArrayOfByte1.length)] = paramArrayOfByte2[k];
      k++;
    }
    return arrayOfByte;
  }

  public static String byteToHex(byte paramByte)
  {
    try
    {
      char[] arrayOfChar1 = { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102 };
      char[] arrayOfChar2 = new char[2];
      arrayOfChar2[0] = arrayOfChar1[(0xF & paramByte >> 4)];
      arrayOfChar2[1] = arrayOfChar1[(paramByte & 0xF)];
      String str = new String(arrayOfChar2);
      return str;
    }
    catch (Exception localException)
    {
    }
    return null;
  }

  public static String encryptRSA(String paramString)
  {
    if ((paramString == null) || ("".equals(paramString)))
      return null;
    try
    {
      BigInteger localBigInteger1 = new BigInteger("C10F7968CFE2C76AC6F0650C877806D4514DE58FC239592D2385BCE5609A84B2A0FBDAF29B05505EAD1FDFEF3D7209ACBF34B5D0A806DF18147EA9C0337D6B5B", 16);
      BigInteger localBigInteger2 = new BigInteger("010001", 16);
      RSAPublicKey localRSAPublicKey = (RSAPublicKey)KeyFactory.getInstance("RSA").generatePublic(new RSAPublicKeySpec(localBigInteger1, localBigInteger2));
      Cipher localCipher = Cipher.getInstance("RSA/ECB/nopadding");
      localCipher.init(1, localRSAPublicKey);
      String str = new String(Base64.encode(a(paramString.getBytes("UTF-8"), 1, localCipher), 0));
      return str;
    }
    catch (Exception localException)
    {
      Log.debug("IMCOMMONS_3.7.0", "Exception in encryptRSA", localException);
    }
    return null;
  }

  public static String getAndroidId(Context paramContext)
  {
    try
    {
      String str2 = Settings.Secure.getString(paramContext.getContentResolver(), "android_id");
      localObject = str2;
      if (localObject == null);
      try
      {
        String str1 = Settings.System.getString(paramContext.getContentResolver(), "android_id");
        localObject = str1;
        return localObject;
      }
      catch (Exception localException2)
      {
        return localObject;
      }
    }
    catch (Exception localException1)
    {
      while (true)
        Object localObject = null;
    }
  }

  public static String getFBId(Context paramContext)
  {
    try
    {
      String[] arrayOfString = { "aid" };
      Cursor localCursor = paramContext.getContentResolver().query(a, arrayOfString, null, null, null);
      if ((localCursor != null) && (localCursor.moveToFirst()))
      {
        str = localCursor.getString(localCursor.getColumnIndex("aid"));
        if (str != null)
        {
          int i = str.length();
          if (i != 0)
            break label106;
        }
        return null;
      }
    }
    catch (Exception localException)
    {
      Log.internal("IMCOMMONS_3.7.0", "Unable to retrieve Facebook attrib id: " + localException);
      return null;
    }
    String str = null;
    label106: return str;
  }

  public static String getIMAppId()
  {
    return appId;
  }

  public static String getODIN1(String paramString)
  {
    if (paramString != null)
      try
      {
        if (!"".equals(paramString.trim()))
        {
          MessageDigest localMessageDigest = MessageDigest.getInstance("SHA-1");
          localMessageDigest.update(paramString.getBytes());
          byte[] arrayOfByte = localMessageDigest.digest();
          StringBuffer localStringBuffer = new StringBuffer();
          for (int i = 0; i < arrayOfByte.length; i++)
            localStringBuffer.append(Integer.toString(256 + (0xFF & arrayOfByte[i]), 16).substring(1));
          String str = localStringBuffer.toString();
          return str;
        }
      }
      catch (Exception localException)
      {
        Log.debug("IMCOMMONS_3.7.0", "Exception in getting ODIN-1", localException);
        return null;
      }
    return "TEST_EMULATOR";
  }

  public static String getRSAKeyVersion()
  {
    return "1";
  }

  public static String getUM5(String paramString)
  {
    if (paramString != null)
      try
      {
        if (!"".equals(paramString.trim()))
        {
          MessageDigest localMessageDigest = MessageDigest.getInstance("MD5");
          localMessageDigest.update(paramString.getBytes());
          byte[] arrayOfByte = localMessageDigest.digest();
          StringBuffer localStringBuffer = new StringBuffer();
          for (int i = 0; i < arrayOfByte.length; i++)
            localStringBuffer.append(Integer.toString(256 + (0xFF & arrayOfByte[i]), 16).substring(1));
          String str = localStringBuffer.toString();
          return str;
        }
      }
      catch (Exception localException)
      {
        Log.debug("IMCOMMONS_3.7.0", "Exception in getting ODIN-1", localException);
        return null;
      }
    return "TEST_EMULATOR";
  }

  public static void setIMAppId(String paramString)
  {
    appId = paramString;
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.inmobi.commons.uid.UIDHelper
 * JD-Core Version:    0.6.2
 */